def scope_test():
    def do_local():
        spam = "local spam"

    def do_nonlocal():
        nonlocal spam
        spam = "nonlocal spam"
    def do_global():
        global spam
        spam = "global spam"
    spam = "test spam"
    do_local()
    print("After local assignment:", spam)
    do_nonlocal()
    print("After nonlocal assignment:", spam)
    do_global()
    print("After global assignment:", spam)

scope_test()
print("In global scope:", spam)


class XXClass:
    def foo(self,name):
        print("Hello, %s." % name)
def bar(self,name):
    print("Got your message: %s" % name)

XXClass.foo = bar

obj = XXClass()
obj.foo("world")


class Warehouse:
   purpose = 'storage'
   region = 'west'

w1 = Warehouse()
print(w1.purpose, w1.region)
w1.region = 'east'
w2 = Warehouse()
print(w2.purpose, w2.region)


def f1(self,x,y):
    return min(x,x+y)
class C:
    f = f1
    def g(self):
        return 'hello world'
    h = g